using System;

namespace Cfg.ConfigValues
{
	public class Time : ConfigValueBase
	{
	    public int Hours { get; set; }
		public int Minutes { get; set; }
		public int Seconds { get; set; }
		public int Milliseconds { get; set; }

		public override void Parse()
		{
			// format hh:mm:ss.fffff

			var segments = FinalizedStringValue.Split(':');
			if (segments.Length > 3)
				throw new InvalidOperationException("Invalid format. Supported format is (h)h:(m)m:(s)s.(ffffff)f");

			int h, m = 0, s = 0, ms = 0;

			h = int.Parse(segments[0]);

			if (segments.Length > 1)
				m = int.Parse(segments[1]);

			if (segments.Length > 2)
			{
				var secondSegments = segments[2].Split('.');
				s = int.Parse(secondSegments[0]);

				if (secondSegments.Length > 1)
					ms = int.Parse(secondSegments[1]);
			}

		    Hours = h;
		    Minutes = m;
		    Seconds = s;
		    Milliseconds = ms;
		}
	}
}